using Domain.Weather;
using MediatR;
using MES.Server.API.Application.Command.Weather;
using MES.Server.API.Dto.Weather;
using Microsoft.AspNetCore.Mvc;
using ReturnValue;

namespace MES.Server.API.Controllers
{
    /// <summary>
    /// 天气信息控制器
    /// </summary>
    [ApiController]
    [Route("api/[controller]")]
    public class WeatherController : ControllerBase
    {
        private readonly IMediator _mediator;
        private readonly ILogger<WeatherController> _logger;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator">中介者</param>
        /// <param name="logger">日志记录器</param>
        public WeatherController(IMediator mediator, ILogger<WeatherController> logger)
        {
            _mediator = mediator;
            _logger = logger;
        }

 

        /// <summary>
        /// 获取模拟天气信息
        /// </summary>
        /// <param name="cityName">城市名称</param>
        /// <param name="days">预报天数，默认7天</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>模拟天气信息</returns>
        [HttpGet("mock")]
        public async Task<ApiResult<WeatherOutPut>> GetMockWeather(
            [FromQuery] string cityName, 
            [FromQuery] int days = 7, 
            CancellationToken cancellationToken = default)
        {
            _logger.LogInformation("收到生成城市 {CityName} 模拟天气信息的请求，预报 {Days} 天", cityName, days);
            var request = new GetMockWeatherCommand(cityName, days);
            return await _mediator.Send(request, cancellationToken);
        }
    }
}
